package com.example.android_common.view.iosdialog;

import com.example.android_common.R;
import com.example.android_common.util.ShowUtils;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class ProgressDialog {
	private Context context;
	private Dialog dialog;
	
	public ProgressDialog(Context context) {
		this.context = context;
	}
	
	public ProgressDialog builder() {
		// 获取Dialog布局
		View view = LayoutInflater.from(context).inflate(
				R.layout.view_progressdialog, null);
		// 定义Dialog布局和参数
		dialog = new Dialog(context, R.style.AlertDialogStyle);
		dialog.setContentView(view);
		dialog.setCanceledOnTouchOutside(false);
		Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = ShowUtils.dip2px(120); // 宽度
        lp.height = ShowUtils.dip2px(120); // 高度
        dialogWindow.setAttributes(lp);
		return this;
	}
	
	public boolean isShowing(){
		if(dialog != null)
			return dialog.isShowing();
		return false;
	}
	
	public void show() {
		if(dialog != null)
			dialog.show();
	}
	public void dismiss(){
		if(dialog != null)
			dialog.dismiss();
	}
}
